package com.easou.ps.master.search;

import org.apache.log4j.Logger;

import com.easou.ps.common.servicehandle.ServiceAddress;
import com.easou.ps.master.rpc.KSRPCProxy;
import com.easou.ps.master.rpc.RPCProxyFactory;
import com.easou.ps.thrift.ks.KnowledgeSearchRequest;

public class SearchTask {
	
	static final Logger LOG = Logger.getLogger("search");
	private KnowledgeSearchRequest query;
	private SearchTarget target;
	private ServiceAddress addr;
	
	private long timeCost = 0;
	
	public long getTimeCost() {
		return timeCost;
	}

	public void setTimeCost(long timeCost) {
		this.timeCost = timeCost;
	}
	
	public SearchTask(KnowledgeSearchRequest request, SearchTarget target, ServiceAddress addr) {
		this.query = request;
		this.target = target;
		this.addr = addr;
	}
	
	public void call() {
		long startTime = System.currentTimeMillis();

		final KSRPCProxy proxy = RPCProxyFactory.getRPCKsProxy(addr);
		proxy.search(query);
		setTimeCost(System.currentTimeMillis() - startTime);
	}

	public SearchTarget getTarget() {
		return target;
	}
}
